﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using Majoopic.WPFClient.Model;
using Majoopic.Engine;
using Majoopic.Service.Model;

namespace Majoopic.WPFClient.ViewModels
{
    public class ImagesViewerViewModel : BaseViewModel
    {
        public ObservableCollection<ImageModel> Images
        {
            get;
            set;
        }

        public ImagesViewerViewModel()
            : base()
        {
            this.Images = new ObservableCollection<ImageModel>();
            Mediator.Current.SubscribeToEvent(EventNames.FileEngineJobCreated, () => 
            {
                Mediator.Current.CurrentFileEngine.ImageScanned += new EventHandler<ImageInformationEventArgs>(CurrentFileEngine_ImageScanned);
            });
        }

        private void CurrentFileEngine_ImageScanned(object sender, ImageInformationEventArgs e)
        {
            this.UIDispatcher.Invoke(new Action(() => this.AddImage(e.Image)));
        }

        private void AddImage(ImageInformation imageInfo)
        {
            this.Images.Add(new ImageModel(imageInfo));

        }
    }
}
